<?php
class Admin_Form_AdminUser_ValidateImage{
	
	static function validate($arrParam = null, $options = null){
		
		$upload = new Zend_File_Transfer_Adapter_Http();
		$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
													'fileConfig'=>'user.ini'));
		$configObj = $config->getConfig('avatar');
	
		$fileInfo = $upload->getFileInfo('avatar');
		$fileName = $fileInfo['avatar']['name'];
		if(!empty($fileName)){
			$options = $configObj['extension'];
			$upload->addValidator('Extension',true,$options,'image')
			 	   ->addValidator('Size',true,array('min'=>$configObj['min'],'max'=>$configObj['max']),'avatar')
				   ->addValidator('ImageSize',true,
									array('minwidth'=>$configObj['thumb-width1'],'minheight'=>$configObj['thumb-height1'],
										'maxwidth'=>$configObj['thumb-width2'],'maxheight'=>$configObj['thumb-height2']),
									'avatar')
			;
			if(!$upload->isValid('avatar')){
				$message = $upload->getMessages();
				$error = current($message);							
			}
		}
		return $error;	
	}
	
}